<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 快聊接口
 */
class FastMessage extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    //快聊留言列表
    public function fastMessageList(){
        $page = input('param.page',1);
        $limit = input('param.limit',10);

        $list = db('fast_message')->order('id desc')->paginate($limit,false,['page'=>$page]);
        $data = tp_builde_page($list);
        $this->success('',$data);
    }

    //快聊发布留言
    public function fastMessageAdd(){
        if(request()->isPost()){
            $data['name'] = input('param.name');
            $data['mobile'] = input('param.mobile');
            $data['content'] = input('param.content');
            $data['wechat'] = input('param.wechat');
            $data['qq'] = input('param.qq');

            $request = db('fast_message')->insert($data);
            if($request){
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }
    }

    //快聊创建群
    public function chatGroupAdd(){
        if(request()->isPost()){
            $data['name'] = input('param.name');
            $data['qq'] = input('param.qq');
            $data['wechat'] = input('param.wechat');
            $data['mobile'] = input('param.mobile');
            $data['type'] = input('param.type');
            $data['number'] = input('param.number');
            $data['attribute'] = input('param.attribute');
            $data['category'] = input('param.category');
            $data['transaction'] = input('param.transaction');
            $data['group_entry'] = input('param.group_entry');

            $result = db('chat_group')->insert($data);
            if($result){
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }
    }

    //快聊群列表
    public function chatGroupList(){
        $where = [];
        input('param.category') && $where['category'] = input('param.category');

        $page = input('param.page',1);
        $limit = input('param.limit',10);

        $list = db('chat_group')->where($where)->order('id desc')->paginate($limit,false,['page'=>$page]);
        $data = tp_builde_page($list);
        $this->success('',$data);
    }

    //推广套餐
    public function promotionPackageList(){
        $list = db('chat_group')->select();

        $this->success('成功',$list);
    }






}
